package com.lwx.test;

import java.util.Arrays;

//两数之和
public class Demo2 {
    public static void main(String[] args) {
        int[]nums = {2,7,11,15};
        int[] indexs = twoSum(nums, 9);
        System.out.println(Arrays.toString(indexs));
    }
    public static int[] twoSum(int[] nums, int target) {
        int[] res = new int[2];
        for (int i = 0; i < nums.length; i++) {
            for (int j = 0; j < nums.length; j++) {
                if(i != j){
                    if(nums[i]+nums[j] == target){
                        if(i<j){
                            res[0] = i;
                            res[1] = j;
                            return res;
                        }else {
                            res[0] = j;
                            res[1] = i;
                            return res;
                        }
                    }
                }
            }
        }
        return res;
    }
}
